package com.qingmu.club.minaapi.custom.logic;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qingmu.club.minaapi.plus.entity.ExamItem;
import com.qingmu.club.minaapi.plus.entity.ExamItemDetail;
import com.qingmu.club.minaapi.plus.service.ExamItemDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ExamItemLogic {


    @Autowired
    ExamItemDetailService examItemDetailService;


    /**
     * 判断答题是否正确
     * @param examItemId
     * @return
     */
    public boolean ItemDetailTrueOrFalse(String examItemId,String examItemDetailIds){

        String[] idArray = examItemDetailIds.split(",");

        QueryWrapper<ExamItemDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ExamItemDetail.EXAM_ITEM_ID,examItemId).eq(ExamItemDetail.IS_TRUE,1);
        List<ExamItemDetail> examItemDetailList = this.examItemDetailService.list(queryWrapper);
        for(String examItemDetailId :  idArray){
            ExamItemDetail examItemDetail = this.examItemDetailService.getById(examItemDetailId);
            if(!examItemDetailList.contains(examItemDetail)){
                return false;
            }
        }
        return true;
    }


}
